package com.wyj.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wyj.mapper.YlrcUserMapper;
import com.wyj.pojo.YlrcUser;
import com.wyj.service.YlrcUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author mac
* @description 针对表【ylrc_user】的数据库操作Service实现
* @createDate 2022-11-18 19:09:58
*/
@Service
public class YlrcUserServiceImpl extends ServiceImpl<YlrcUserMapper, YlrcUser>
implements YlrcUserService {

    @Autowired
    YlrcUserMapper ylrcUserMapper;

    @Override
    public int deleteUser(int id) {
        int i = ylrcUserMapper.deleteById(id);

        //删除成功
        if (i >= 0) return 1;

        //删除失败
        return 0;
    }

    @Override
    public int addUser(YlrcUser ylrcUser) {

        int insert = ylrcUserMapper.insert(ylrcUser);

        //增加成功
        if (insert >= 0) return 1;

        //增加失败
        return 0;
    }

    @Override
    public List<Map<String, Object>> getUserAndRoles(String userName) {
        return ylrcUserMapper.getUserAndRoles(userName);
    }

    @Override
    public int deleteUserAndRole(String username, int roleId) {
        QueryWrapper<YlrcUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",username);
        queryWrapper.eq("role_id",roleId);
        return ylrcUserMapper.delete(queryWrapper);
    }

    @Override
    public List<Map<String, Object>> getUserAndMenus(String username) {
        return ylrcUserMapper.getUserAndMenus(username);
    }


}
